package com.share.shrimpcolo;

/**
 * 有13个人围成一圈，顺序排号，从第3个开始报数（从1到5报数），凡报到5的人退出圈子，下一个继续从1开始报，输出退出顺序。
 * 
 * @author Johnny Tam
 *
 */
public class TestDemo {
	public static void main(String[] args) {
		int people[] = new int[13];

		for (int i = 0; i < people.length; i++) {
			people[i] = i+1;
		}
		for (int boo : people) {
			System.out.print(boo + "\t");
		}

		int start = 2;//第三位开始, 0, 1, 2		
		final int NUMBER = 13;
		int currentN = NUMBER;
		int IndexJ = 0;

		System.out.println("\n\n出圈顺序为：");
		while (currentN > 0) {
			start = start % NUMBER;//关键点，使用 % 来计算

			if (people[start] != -1) {
				IndexJ++;
				if (IndexJ == 5) {
					people[start] = -1;
					System.out.print((start + 1) + "\t");
					currentN--;// 总人数减1
					IndexJ = 0;// 到5从头数
				}
			}
			start++;
		}
	}
}